<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./lib/vue_2.5.22.js"></script>
  <!-- 1、引入js库 -->
  <script src="./lib/vue-router_3.0.2.js"></script>
</head>

<body>

  <div id="app">
    <!-- 2、 创建路由标签 -->
    <!-- router-link 会被解析成a标签 -->
    <!-- to 会被解析成href -->
    <router-link to='/login'>Login</router-link>
    <router-link to='/register'>Register</router-link>

    <!-- 3、创建路由占位符，填充位 -->
    <router-view></router-view>
  </div>

  <script>

    var Login = {
      template: `
        <h2>登录</h2>
      `
    }

    var Register = {
      template: `
        <h2>注册</h2>
      `
    }

    // 4、创建路由规则
    var router = new VueRouter({
      routes: [
        { path: '/', redirect: '/login' },
        { path: '/login', component: Login },
        { path: '/register', component: Register },
      ]
    })

    var vm = new Vue({
      el: '#app',
      data: {},
      router

    })
  </script>
</body>

</html>